$NG.AllReady(function (page, { useValuesChange,useDataIndexChange,useUpdateRows,useUpdateRow }) {
    const mstform = $NG.getCmpApi("p_form_ssfill_m")
    const dgrid = $NG.getCmpApi("p_form_ssfill_d")
    let param = parseUrlParams(window.location.href)

    //获取相关信息
    if(param.intype == 'click'){
        getYgTaskInfo()
        function getYgTaskInfo(){
            $NG.execServer("getYgTaskInfo",{phid:param.sourceid},(res)=>{
                if(res.count == 0) return 
                const _data = JSON.parse(res.data)
                console.log(_data);
                const form = _data[0].extendObjects
                const dArr = _data.reduce((value,item)=>{
                    value.push(item.extendObjects)
                    return value
                },[])
                $NG.updateState((updater)=>{
                    updater.data.p_form_ssfill_m.setProps({
                        u_name:{
                            label:form.ry_name,
                            value:form.u_name,
                        },
                        phid_org:{
                            label:$NG.getUser().orgName,
                            value:$NG.getUser().orgID,
                        },
                        phid_pc:{
                            label:form.bill_name,
                            value:form.phid_pc
                        },
                        u_employment_type:form.u_employment_type,
                        u_source_phid:form.phid
                    })
                })
                dgrid.addRows(dArr.reduce((value,item)=>{
                    value.push({
                        u_type:item.u_type,
                        u_score:item.u_score,
                        u_plan_content:item.u_plan_content,
                        u_plan_finishdt:item.u_plan_finishdt
                    })
                    return value
                },[]))
                dgrid.refreshView()
            })
        }
    }
    
	useUpdateRows(({ args }) => {
		console.log(`表格监听`);
		const _d1arr = dgrid.getRows();
		let u_self_score = 0;
		let u_reevaluate_score = 0;
		_d1arr.forEach((element) => {
			u_self_score += element.u_self_score ? element.u_self_score : 0;
			u_reevaluate_score += element.u_reevaluate_score
				? element.u_reevaluate_score
				: 0;
		});
		console.log("数组", u_reevaluate_score, u_self_score);
		$NG.updateState((updater) => {
			updater.data.p_form_ssfill_m.setProps({
				u_self_score: u_self_score,
				u_reevaluate_score: u_reevaluate_score,
			});
		});
	}, "p_form_ssfill_d");


    (select a.tax_register_addr, a.phid, a.compno, a.compname, a.app_status, a.detail_add, a.regdate, a.reg_fund, a.e_mail, a.linkman, a.phone, a.mainsell, a.psn, a.iden_card_id, a.suppclass_main, b.parentid, b.sname, a.three_to_one  from  pms3_spp_eval_acs_supp a  left join suppclass b on a.suppclass_main=b.phid where user_isrd<>'1' or user_isrd is null )aa

    useValuesChange(({args})=>{
        getYgstbInfo()
        cntMFilter()
    },"p_form_ssfill_m.phid_pc")
    useValuesChange(({args})=>{
        getYgstbInfo()
    },"p_form_ssfill_m.u_name")
    function getYgstbInfo(){
        const phid_pc = mstform.getItem("phid_pc").getValue()
        const name = mstform.getItem("u_name").getValue()
        $NG.execServer("getYgstbInfo",{phid_pc,name},(res)=>{
            if(res.count == 0) return 
            const _data = JSON.parse(res.data)
            console.log(_data);
            const form = _data[0].extendObjects
            const dArr = _data.reduce((value,item)=>{
                value.push(item.extendObjects)
                return value
            },[])
            $NG.updateState((updater)=>{
                updater.data.p_form_ssfill_m.setProps({
                    u_name:{
                        label:form.ry_name,
                        value:form.u_name,
                    },
                    phid_org:{
                        label:$NG.getUser().orgName,
                        value:$NG.getUser().orgID,
                    },
                    phid_pc:{
                        label:form.bill_name,
                        value:form.phid_pc
                    },
                    u_employment_type:form.u_employment_type,
                    u_source_phid:form.phid
                })
            })
            dgrid.addRows(dArr.reduce((value,item)=>{
                value.push({
                    u_type:item.u_type,
                    u_score:item.u_score,
                    u_plan_content:item.u_plan_content,
                    u_plan_finishdt:item.u_plan_finishdt
                })
                return value
            },[]))
            dgrid.refreshView()
        })
    }

    cntMFilter()
    function cntMFilter() {
		if (!mstform.getItem("phid_pc").getValue()) {
			return;
		}
		$NG.updateUI((updater, state) => {
			updater.fieldSetForm.p_form_ssfill_m.u_name.setProps({
				onBeforeOpen: async () => {
					var phid_pc = $NG
						.getCmpApi("p_form_ssfill_m")
						.getItem("phid_pc")
						.getValue();
					if (!phid_pc) {
						$NG.alert("请先选择项目");
						return false;
					} else {
						return true;
					}
				},
				...(!!$NG
					.getCmpApi("p_form_ssfill_m")
					.getItem("phid_pc")
					.getValue() && {
					clientSqlFilter: {
						xm: $NG
							.getCmpApi("p_form_ssfill_m")
							.getItem("phid_pc")
							.getValue(),
					},
				}),
			});
		});
	}

    function parseUrlParams(url) {
        const paramsObj = {};
        const queryString = url.split('?')[1];
        const paramPairs = queryString.split('&');
        paramPairs.forEach((paramPair) => {
            const [key, value] = paramPair.split('=');
            const decodedValue = decodeURIComponent(value);
            paramsObj[key] = decodedValue;
        });
        return paramsObj;
    }

})